# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
        
class Club_DownloadGame(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))
        clubName = "AT_"
        if "clubName" in args:
            clubName = args["clubName"]

        clubHomePageLayer = poco("ClubHomePageLayer")

        if not clubHomePageLayer.exists():
            return False


        btnMyJoinPress = poco("my_join_press")
        btnMyJoinNor = poco("my_join_nor")
        
        if btnMyJoinNor.exists():
            self.clickButton(btnMyJoinNor)

        myCreateList = clubHomePageLayer.offspring("my_join_list")
        clubItems = myCreateList.offspring("my_join_item")
        isClickClub = False
        for item in clubItems:
            txtName = item.offspring("club_name").get_text()
            if txtName.startswith(clubName):
                self.clickButton(item)
                isClickClub = True
                break

        assert_equal(isClickClub, True, "进入俱乐部检测下载失败")
        if not isClickClub:
            return False

        clubPageLayer = poco("ClubPageLayer")
        downloadTipsDlg = clubPageLayer.offspring("LBTipsLayer")
        if downloadTipsDlg.exists():
            # 先下载游戏 
            btnDownload = downloadTipsDlg.offspring("cancel_btn_2")
            btnDownload.click([0.5, 0.5])
            
            while True:
                quickDownloadGameLayer = poco("QuickDownloadGameLayer") # 等待下载子游戏，10分钟后超时
                if not quickDownloadGameLayer.exists():
                    break
            
            clubPageLayer = poco("ClubPageLayer")
            downloadTipsDlg = clubPageLayer.offspring("LBTipsLayer")
            btnOK = downloadTipsDlg.offspring("ok_btn_1")
            btnOK.click([0.5, 0.5])

        btnBack = clubPageLayer.offspring("back_btn")
        self.clickButton(btnBack)
            
        return True
        
_instance = Club_DownloadGame()
runTest = _instance.runTest
